<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 插入元素
      {
        let a = [1, 2, 3];

        a.splice(1, 0, 3);
        console.log(a); //[1,3,2,3]
      }

      // 删除元素
      {
        let a = [1, 2, 3];

        a.splice(1, 1);
        console.log(a); //[1,3]
      }

      // 删除元素,再插入
      {
        let a = [1, 2, 3];

        a.splice(1, 1, 4);
        console.log(a); //[1,4,3]
      }
    </script>
  </body>
</html>
